﻿<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html>
<!-- saved from url=(0033)http://research.microsoft.com/pex -->
<head><link rel="StyleSheet" href="er.common.css" type="text/css" /><script src="er.common.js" type="text/javascript"> </script><link rel="SHORTCUT ICON" href="favicon.ico" /><link rel="icon" href="favicon.ico" type="image/x-icon" /><title>C:\Users\AO\Documents\Visual Studio 2010\AutomaTones3\automatones\AutomaTones\AutomaTones\Model\Automaton Model\Cell.cs</title></head><body><div class="banner"></div><h2 id="top">C:\Users\AO\Documents\Visual Studio 2010\AutomaTones3\automatones\AutomaTones\AutomaTones\Model\Automaton Model\Cell.cs</h2><div class="toggle"><p class="copyright"><a class="usercodeundertestcovered">user code under test</a>, 
  <span class="usercodeundertestnotcovered">user code under test (not covered)</span>, 
  <a class="userortestcodecovered">user code or test</a>, 
  <span class="userortestcodenotcovered">user code or test (not covered)</span>,
  <span class="tagged">tagged</span></p><table><tr><th>Methods</th></tr><tr><th /></tr></table><div class="toggle"><a class="button" href="#ID0EL">first</a><pre class="coverage">using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using Microsoft.Pex.Framework;

namespace AutomaTones.Model.Automaton_Model {
    /// &lt;summary&gt;
    /// A cell with a given state decided by one or more rules.
    /// Multiple triggers can be attached to react to different states - by publishing events.
    /// &lt;/summary&gt;
    /// &lt;author&gt;Anders Øland / anoe@itu.dk&lt;/author&gt;
    [Serializable]
    public class Cell {
        /// &lt;summary&gt;
        /// The state of the cell.
        /// &lt;/summary&gt;
        public State State { get; protected internal set; }
        
        /// &lt;summary&gt;
        /// The rule governing the state &amp; evolution of this cell
        /// &lt;/summary&gt;
        public Rule Rule { get; protected internal set; }
        
        <span id="ID0EL"><a class="button" href="#top">top</a></span><a class="userortestcodecovered">private HashSet&lt;Trigger&gt; _triggers = new HashSet&lt;Trigger&gt;();</a>

        /// &lt;summary&gt;
        /// The set of triggers for this cell. May be empty.
        /// &lt;/summary&gt;
        public HashSet&lt;Trigger&gt; Triggers {
            get { return _triggers; }
            protected internal set {
                Contract.Requires(null != value);
                Contract.Requires(Contract.ForAll&lt;Trigger&gt;(value, v =&gt; null != v));
                Contract.Ensures(Triggers == value);
                _triggers = value;
            }
        }

        /// &lt;summary&gt;
        /// Add a trigger to this cell.
        /// &lt;/summary&gt;
        /// &lt;param name="trigger"&gt;&lt;/param&gt;
        public void AddTrigger(Trigger trigger) {
            Contract.Requires(null != trigger);
            Contract.Ensures(Triggers.Contains(trigger));
            _triggers.Add(trigger);
        }

        /// &lt;summary&gt;
        /// Remove a trigger from this cell.
        /// &lt;/summary&gt;
        /// &lt;param name="trigger"&gt;&lt;/param&gt;
        public void RemoveTrigger(Trigger trigger) {
            Contract.Requires(null != trigger);
            Contract.Ensures(!Triggers.Contains(trigger));
            _triggers.Remove(trigger);
        }

        <a class="userortestcodecovered">public Cell(Rule rule, int stateMin = 0, int stateMax = 1, int stateInit = 0)</a> <a class="userortestcodecovered">{</a>
            Contract.Requires(null != rule);
            Contract.Requires(stateMin &lt; stateMax);
            Contract.Requires(stateMin &lt;= stateInit &amp;&amp; stateMax &gt;= stateInit);
            Contract.Ensures(Rule.Equals(rule));
            Contract.Ensures(State.SpaceMin == stateMin &amp;&amp; State.SpaceMax == stateMax &amp;&amp; State.CurrentState == stateInit);
            <a class="userortestcodecovered">Rule = rule;</a>
            <a class="userortestcodecovered">State = new State(stateMin, stateMax, stateInit);</a>
        <a class="userortestcodecovered">}</a>

        [ContractInvariantMethod]
        private void ObjInvariant() {
            Contract.Invariant(null != State);
            Contract.Invariant(null != Rule);
        }
    }
}
</pre></div></div><hr /><table width="100%"><tr><td valign="top"><span class="copyright">Copyright (c) Microsoft Corporation. All rights reserved.</span><br /><span class="button" onclick="copySourceToClipboard()">Copy full source to clipboard</span></td></tr></table><div id="debugdiv"> </div></body></html>